<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="cn">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>修改日常经费信息</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.7 -->
    <!--link导入外部的css，js样式，如果导入的资源和本页面在同一个文件夹下，直接文件名即可-->
    <link rel="stylesheet" th:href="@{/asserts/bower_components/bootstrap/dist/css/bootstrap.min.css}">
    <!-- jQuery 3 -->
    <script th:src="@{/asserts/bower_components/jquery/dist/jquery.min.js}"></script>
    <!-- Bootstrap 3.3.7 -->
    <script th:src="@{/asserts/bower_components/bootstrap/dist/js/bootstrap.min.js}"></script>
    <!-- Font Awesome -->
    <link rel="stylesheet" th:href="@{/asserts/bower_components/font-awesome/css/font-awesome.min.css}">
    <!-- Ionicons -->
    <link rel="stylesheet" th:href="@{/asserts/bower_components/Ionicons/css/ionicons.min.css}">
    <!-- DataTables -->
    <link rel="stylesheet" th:href="@{/asserts/bower_components/datatables.net-bs/css/dataTables.bootstrap.min.css}">
    <!-- Theme style -->
    <link rel="stylesheet" th:href="@{/asserts/dist/css/AdminLTE.min.css}">

    <!-- Google Font -->
    <link rel="stylesheet"
          href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">

</head>
<body>
<div class="wrapper">
    <!-- Content Wrapper. Contains page content -->
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h4>
            <i class="fa fa-edit"></i> 修改日常经费信息
        </h4>
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box" style="width: 70%;margin: 0 auto;">
                    <div class="box-body">
                        <form class="form-horizontal" id="modifyForm">
                            <h4 style="text-align: center;font-weight: bold">修改经费信息</h4>
                            <div class="form-group">
                                <label class="col-sm-4 control-label"><span
                                        style="color: red;">*</span> 发生日期：</label>
                                <div class="col-sm-5">
                                    <input id="dsDate" type="date" class="form-control" autocomplete="off" name="dsDate"
                                           th:value="${#dates.format(ds.dsDate,'yyyy-MM-dd')}"
                                           required>
                                </div>
                                <p style="line-height: 35px;">&nbsp;</p>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label"> 交通打车/滴滴：</label>
                                <div class="col-sm-5">
                                    <input id="dsTrafficTaxi" type="text" class="form-control" autocomplete="off"
                                           name="dsTrafficTaxi"
                                           th:value="${ds.dsTrafficTaxi}"
                                           placeholder="请输入打车(滴滴)费用"
                                           onchange="if(/\D/.test(value)){layer.msg('格式不对哦!请输入数字', {icon: 0, time: 1500});value='';}">
                                </div>
                                <p style="line-height: 35px;">元</p>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label"> 交通费-其他：</label>
                                <div class="col-sm-5">
                                    <input id="dsTrafficOther" type="text" class="form-control" autocomplete="off"
                                           name="dsTrafficOther"
                                           th:value="${ds.dsTrafficOther}"
                                           placeholder="请输入其他的交通费用"
                                           onchange="if(/\D/.test(value)){layer.msg('格式不对哦!请输入数字', {icon: 0, time: 1500});value='';}">
                                </div>
                                <p style="line-height: 35px;">元</p>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label"> 交通费-合计：</label>
                                <div class="col-sm-5" style="float: left;">
                                    <input id="dsTrafficTotal" type="text" class="form-control" autocomplete="off"
                                           name="dsTrafficTotal"
                                           th:value="${ds.dsTrafficTotal}"
                                           placeholder="请输入交通费-合计"
                                           onchange="if(/\D/.test(value)){layer.msg('格式不对哦!请输入数字', {icon: 0, time: 1500});value='';}">
                                </div>
                                <p style="line-height: 35px;">元</p>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label"> 住宿费：</label>
                                <div class="col-sm-5">
                                    <input id="dsStayTotalprice" type="text" class="form-control" autocomplete="off"
                                           name="dsStayTotalprice"
                                           th:value="${ds.dsStayTotalprice}"
                                           placeholder="请输入住宿费"
                                           onchange="if(/\D/.test(value)){layer.msg('格式不对哦!请输入数字', {icon: 0, time: 1500});value='';}">
                                </div>
                                <p style="line-height: 35px;">元</p>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label"> 住宿间数：</label>
                                <div class="col-sm-5">
                                    <input type="text" class="form-control" autocomplete="off" name="dsStayCount"
                                           th:value="${ds.dsStayCount}"
                                           placeholder="请输入住宿间数"
                                           onchange="if(/\D/g.test(value)){layer.msg('格式不对哦!请输入整数', {icon: 0, time: 1500});value='';}">
                                </div>
                                <p style="line-height: 35px;">间</p>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label"> 住宿人：</label>
                                <div class="col-sm-5">
                                    <input type="tel" class="form-control" autocomplete="off" name="dsStayPeople"
                                           th:value="${ds.dsStayPeople}"
                                           placeholder="请输入人名,逗号隔开,同性必须合住"
                                           onchange="if(/[\d]/g.test(value)){layer.msg('格式不对哦!请输入字母或中文', {icon: 0, time: 1500});value='';}">
                                </div>
                                <p style="line-height: 35px;">&nbsp;</p>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label"> 住宿单价：</label>
                                <div class="col-sm-5">
                                    <input id="dsStayUnitprice" type="text" class="form-control" autocomplete="off"
                                           name="dsStayUnitprice"
                                           th:value="${ds.dsStayUnitprice}"
                                           placeholder="请输入住宿单价"
                                           onchange="if(/\D/.test(value)){layer.msg('格式不对哦!请输入数字', {icon: 0, time: 1500});value='';}">
                                </div>
                                <p style="line-height: 35px;">元</p>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label"> 学生招待：</label>
                                <div class="col-sm-5">
                                    <input id="dsEntertainStu" type="text" class="form-control" autocomplete="off"
                                           name="dsEntertainStu"
                                           th:value="${ds.dsEntertainStu}"
                                           placeholder="请输入学生招待费用"
                                           onchange="if(/\D/.test(value)){layer.msg('格式不对哦!请输入数字', {icon: 0, time: 1500});value='';}">
                                </div>
                                <p style="line-height: 35px;">元</p>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label"> 领导招待：</label>
                                <div class="col-sm-5">
                                    <input id="dsEntertainLeader" type="text" class="form-control" autocomplete="off"
                                           name="dsEntertainLeader"
                                           th:value="${ds.dsEntertainLeader}"
                                           placeholder="请输入领导招待费用"
                                           onchange="if(/\D/.test(value)){layer.msg('格式不对哦!请输入数字', {icon: 0, time: 1500});value='';}">
                                </div>
                                <p style="line-height: 35px;">元</p>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label"> 劳务/佣金：</label>
                                <div class="col-sm-5">
                                    <input id="dsServices" type="text" class="form-control" autocomplete="off"
                                           name="dsServices"
                                           th:value="${ds.dsServices}"
                                           placeholder="请输入劳务/佣金费用"
                                           onchange="if(/\D/.test(value)){layer.msg('格式不对哦!请输入数字', {icon: 0, time: 1500});value='';}">
                                </div>
                                <p style="line-height: 35px;">元</p>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label"> 其它费用：</label>
                                <div class="col-sm-5">
                                    <input id="dsOther" type="text" class="form-control" autocomplete="off"
                                           name="dsOther"
                                           th:value="${ds.dsOther}"
                                           placeholder="请输入其它费用"
                                           onchange="if(/\D/.test(value)){layer.msg('格式不对哦!请输入数字', {icon: 0, time: 1500});value='';}">
                                </div>
                                <p style="line-height: 35px;">元</p>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label"> 其它费用说明：</label>
                                <div class="col-sm-5">
                                    <textarea class="form-control" autocomplete="off" rows="3" cols="40"
                                              name="dsOtherState"
                                              placeholder="请填写关于其它费用的说明...">[[${ds.dsOtherState}]]</textarea>
                                </div>
                                <p style="line-height: 75px;">&nbsp;</p>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label"><span
                                        style="color: red;">*</span> 员工：</label>
                                <div class="col-sm-5">
                                    <select name="dsSellerUid" id="dsSellerUid" class="form-control" required>
                                        <option disabled value="">--请选择员工--</option>
                                        <option th:each="seller:${sellerList}"
                                                th:selected="${seller.personname==ds.dsSeller}"
                                                th:value="${seller.uid}">[[${seller.personname }]]
                                        </option>
                                    </select>
                                </div>
                                <p style="line-height: 35px;">&nbsp;</p>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label"><span
                                        style="color: red;">*</span> 小计：</label>
                                <div class="col-sm-5">
                                    <input id="dsTotal" type="text" class="form-control" autocomplete="off"
                                           name="dsTotal"
                                           required th:value="${ds.dsTotal}"
                                           placeholder="必填字段，请输入小计"
                                           onchange="if(/\D/.test(value)){layer.msg('格式不对哦!请输入数字', {icon: 0, time: 1500});value='';}">
                                </div>
                                <p style="line-height: 35px;">元</p>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label"> 备注：</label>
                                <div class="col-sm-5">
                                    <textarea class="form-control" autocomplete="off" rows="3" cols="40" name="dsRemark"
                                              placeholder="填写备注信息...">[[${ds.dsRemark}]]</textarea>
                                </div>
                            </div>
                            <br>
                            <div class="form-group">
                                <div style="text-align: center;">
                                    <a th:if="${(cdscDate ==''||cdscDate==null) && (cdscSeller ==''||cdscSeller==null) && (cdscPeople ==''||cdscPeople==null)}"
                                       class="btn btn-danger"
                                       th:href="@{dsShow(currentPage=${currentPage},pageSize=${pageSize})}">
                                        <i class="fa fa-backward"></i>&nbsp;返&nbsp;回
                                    </a>&nbsp;
                                    <a th:if="${!((cdscDate ==''||cdscDate==null) && (cdscSeller ==''||cdscSeller==null) && (cdscPeople ==''||cdscPeople==null))}"
                                       class="btn btn-danger"
                                       th:href="@{dsSearchShow(currentPage=${currentPage},pageSize=${pageSize},cdscDate=${cdscDate},cdscSeller=${cdscSeller},cdscPeople=${cdscPeople})}">
                                        <i class="fa fa-backward"></i>&nbsp;返&nbsp;回
                                    </a>&nbsp;
                                    <button type="reset" class="btn btn-info" id="resetBtn"
                                            onclick="layer.msg('重置成功！', {icon: 1, time: 1500});">
                                        <i class="fa fa-repeat"></i>&nbsp;重&nbsp;置
                                    </button>&nbsp;
                                    <button type="button" class="btn btn-success"
                                            th:onclick="modifySubmit([[${ds.dsId}]])">
                                        &nbsp;&nbsp;&nbsp;<i class="fa fa-check-square"></i>&nbsp;&nbsp;&nbsp;提&nbsp;&nbsp;&nbsp;交&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    </button>
                                </div>
                            </div>
                            <input id="currentPage" th:value="${currentPage}" hidden>
                            <input id="pageSize" th:value="${pageSize}" hidden>
                            <input id="cdscDate" th:value="${cdscDate}" hidden>
                            <input id="cdscSeller" th:value="${cdscSeller}" hidden>
                            <input id="cdscPeople" th:value="${cdscPeople}" hidden>
                        </form>
                    </div>
                    <!-- /.box-body -->
                </div>
                <!-- /.box -->
            </div>
            <!-- /.col -->
        </div>
        <!-- /.row -->
    </section>
    <!-- /.content -->
</div>
<!-- ./wrapper -->

<!-- DataTables -->
<script th:src="@{/asserts/bower_components/datatables.net/js/jquery.dataTables.min.js}"></script>
<script th:src="@{/asserts/bower_components/datatables.net-bs/js/dataTables.bootstrap.min.js}"></script>
<!-- SlimScroll -->
<script th:src="@{/asserts/bower_components/jquery-slimscroll/jquery.slimscroll.min.js}"></script>
<!-- FastClick -->
<script th:src="@{/asserts/bower_components/fastclick/lib/fastclick.js}"></script>
<!-- AdminLTE App -->
<script th:src="@{/asserts/dist/js/adminlte.min.js}"></script>
<!-- AdminLTE for demo purposes -->
<script th:src="@{/asserts/dist/js/demo.js}"></script>
<!-- page script -->
<script th:src="@{/asserts/Apolar_sh/lib/layer/2.4/layer.js}"></script>
</body>
<script>
    function trafficTotal() {
        var dsTrafficTaxi = $("#dsTrafficTaxi").val();
        var dsTrafficOther = $("#dsTrafficOther").val();
        if (dsTrafficTaxi === '') {
            dsTrafficTaxi = 0;
        }
        if (dsTrafficOther === '') {
            dsTrafficOther = 0;
        }
        document.getElementById("dsTrafficTotal").value = parseFloat(dsTrafficTaxi) + parseFloat(dsTrafficOther);
    }

    $("#dsTrafficTotal").focus(trafficTotal)

    $("#dsTotal").focus(total)

    function total() {
        var dsStayTotalprice = $("#dsStayTotalprice").val();
        var dsEntertainStu = $("#dsEntertainStu").val();
        var dsEntertainLeader = $("#dsEntertainLeader").val();
        var dsServices = $("#dsServices").val();
        var dsOther = $("#dsOther").val();
        var dsTrafficTaxi = $("#dsTrafficTaxi").val();
        var dsTrafficOther = $("#dsTrafficOther").val();
        if (dsTrafficTaxi === '') {
            dsTrafficTaxi = 0;
        }
        if (dsTrafficOther === '') {
            dsTrafficOther = 0;
        }
        if (dsStayTotalprice === '') {
            dsStayTotalprice = 0;
        }
        if (dsEntertainStu === '') {
            dsEntertainStu = 0;
        }
        if (dsEntertainLeader === '') {
            dsEntertainLeader = 0;
        }
        if (dsServices === '') {
            dsServices = 0;
        }
        if (dsOther === '') {
            dsOther = 0;
        }
        document.getElementById("dsTotal").value = parseFloat(dsTrafficTaxi) + parseFloat(dsTrafficOther) + parseFloat(dsStayTotalprice) + parseFloat(dsEntertainStu) + parseFloat(dsEntertainLeader) + parseFloat(dsServices) + parseFloat(dsOther);
    }
</script>
<script>
    function modifySubmit(dsId) {

        var dsDate = $("#dsDate").val();
        var dsSellerUid = $("#dsSellerUid").val();
        if (dsDate === '') {
            layer.msg('亲，日期不能为空哦！', {
                icon: 0,
                time: 2000
            });
        } else if (dsSellerUid === '') {
            layer.msg('亲，员工不能为空哦！', {
                icon: 0,
                time: 2000
            });
        } else {
            trafficTotal();
            total()
            layer.confirm("确认提交吗？",
                {
                    btn: ['确定', '取消']
                },
                function () {
                    var pageSize = $("#pageSize").val();
                    var currentPage = $("#currentPage").val();
                    var cdscDate = $("#cdscDate").val();
                    var cdscSeller = $("#cdscSeller").val();
                    var cdscPeople = $("#cdscPeople").val();
                    $.ajax({
                        type: 'POST',
                        url: './dsModify?dsId=' + dsId,
                        data: $("#modifyForm").serialize(),
                        success: function (data) {
                            if (data.id === 0) {
                                layer.msg(data.data, {
                                    icon: 1,
                                    time: 500
                                });
                                setTimeout(function () {
                                    if (cdscDate === "" && cdscSeller === "" && cdscPeople === "") {
                                        location.replace('[[${#httpServletRequest.getContextPath()}]]' + '/ds/dsShow?currentPage=' + currentPage + '&pageSize=' + pageSize);
                                    } else {
                                        location.replace('[[${#httpServletRequest.getContextPath()}]]' + '/ds/dsSearchShow?currentPage=' + currentPage + '&pageSize=' + pageSize + '&cdscDate=' + cdscDate + '&cdscSeller=' + cdscSeller + '&cdscPeople=' + cdscPeople);
                                    }
                                }, 500);
                            } else {
                                layer.msg(data.data, {
                                    icon: 0,
                                    time: 2000
                                });
                            }
                        },
                        error: function (data) {
                            console.log(data.msg);
                        }
                    });
                },
                function () {
                    layer.msg("已取消！", {
                        icon: 0,
                        time: 500
                    });
                    return false;
                }
            );
        }
    }
</script>
</html>